﻿namespace Leetcode.N1114.V3;

using System.Threading;
public class Foo
{
    private readonly SemaphoreSlim semaphore2 = new SemaphoreSlim(0, 1);
    private readonly SemaphoreSlim semaphore3 = new SemaphoreSlim(0, 1);

    public Foo()
    {
    }

    public void First(Action printFirst)
    {
        printFirst();
        this.semaphore2.Release();
    }

    public void Second(Action printSecond)
    {
        this.semaphore2.Wait();
        printSecond();
        this.semaphore3.Release();
    }

    public void Third(Action printThird)
    {
        this.semaphore3.Wait();
        printThird();
    }
}